<?php
require_once("lib/auth/session.php");
require_once("lib/auth/user.php");
require_once("lib/api.php");

$api = new api();

if (isset($_GET['name'])) {
    $username = $_GET['name'];
    if (!is_numeric($userid)) {
        $api->setYouFail("Needs to be a string.");
    } elseif (!($userid = name2Id($username))) {
        $api->setFail("No user with that name found");
    } elseif (loggedIn() == $userid) {
        $api->setReturn("numberOfPosts",getNumberOfPosts());
        $api->setReturn("averageHate",getAverageHate());
        $api->setOk();
    } else {
        
        $api->setOk();
        $api->setReturn("numberOfPosts",getNumberOfPosts($userid));
        $api->setReturn("averageHate",getAverageHate($userid));
    }
}
$api->returnResponse();
?>